# Integration Tests Makefile

CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -g -I../../include
LIBPATH ?= ../../build
LIBNAME ?= gudb
LDFLAGS = -L$(LIBPATH) -l$(LIBNAME) -lpthread -lz

# Integration test sources
TESTS = test_simple test_wal test_integration test_transaction test_server test_client test_network_integration

all: $(TESTS)

# Build the main library first if it doesn't exist
$(LIBPATH)/lib$(LIBNAME).a:
	$(MAKE) -C ../../build

test_simple: test_simple.c $(LIBPATH)/lib$(LIBNAME).a
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

test_wal: test_wal.c $(LIBPATH)/lib$(LIBNAME).a
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

test_integration: test_integration.c $(LIBPATH)/lib$(LIBNAME).a
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

test_transaction: test_transaction.c $(LIBPATH)/lib$(LIBNAME).a
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

test_server: test_server.c $(LIBPATH)/lib$(LIBNAME).a
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

test_client: test_client.c
	$(CC) $(CFLAGS) -o $@ $<

test_network_integration: test_network_integration.c $(LIBPATH)/lib$(LIBNAME).a
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

clean:
	rm -f $(TESTS) *.o *.dSYM

.PHONY: all clean